function MouseControl()
{
	canvas.onmousemove = MouseMoveListener;
	canvas.onclick = MouseClickListener;
	
	function MouseMoveListener(evt)
	{
		AdjustMousePosition(evt); //마우스의 커서 위치를 리턴	
	}
	
	function MouseClickListener(evt)
	{
		AdjustClickedMousePosition(evt); //마우스가 클릭된 위치를 리턴	
	}
	
	function MouseOutListener(evt)
	{
		AdjustMousePosition(evt);
	}
	
	function AdjustMousePosition(evt) 
	{
		var rect = evt.target.getBoundingClientRect();
		mPos.X = evt.clientX - rect.left;
		mPos.Y = evt.clientY - rect.top;
	}
	
	function AdjustClickedMousePosition(evt) 
	{
		var rect = evt.target.getBoundingClientRect();
		mClickedPos.X = evt.clientX - rect.left;
		mClickedPos.Y = evt.clientY - rect.top;
		
		if(gameStartFlag)
		{
			mClickedMapPos.X = Math.floor(mClickedPos.X / startNodes[0].width);
			mClickedMapPos.Y = Math.floor(mClickedPos.Y / startNodes[0].height);
		
			SelectedNodeCheck(mClickedPos);
		}
		
		if(showMenuFlag)
		{
			SelectedNumberCheck();
			
		}
	}	
}

function SelectedNodeCheck(mPos)
{
	for(var i = 0; i < numberOfNode; i++)
	{
		if((mPos.X >= startNodes[i].position.X && mPos.X <= startNodes[i].position.X + startNodes[i].width)
			&& (mPos.Y >= startNodes[i].position.Y && mPos.Y <= startNodes[i].position.Y + startNodes[i].height))
			{
				selectedNode = i;
			}
	}
	
	startNodes[selectedNode].isSelected = true;
	
	
}

function SelectedNumberCheck(mPos)
{
	for(var i = 0; i < 4; i++)
	{
		if((mClickedPos.X >= numbers[i].position.X && mClickedPos.X <= numbers[i].position.X + numbers[i].width)
			&& (mClickedPos.Y >= numbers[i].position.Y && mClickedPos.Y <= numbers[i].position.Y + numbers[i].height))
			{
				selectedNumber = numbers[i].idx;
				check.position.X = numbers[i].position.X + 10;
				check.position.Y = numbers[i].position.Y - 10;					
			}
		else selectdNumber = -1;
	
	}
	
	if((mClickedPos.X >= startBtn.position.X && mClickedPos.X <= startBtn.position.X + startBtn.width)
			&& (mClickedPos.Y >= startBtn.position.Y && mClickedPos.Y <= startBtn.position.Y + startBtn.height))
			{
				startBtn.isSelected = true;
				showMenuFlag = false;	
				gameStartFlag = true;	
				InitGame();			
			}
}	